#import "FavouritesViewController.h"
#import "SongsCustomCell.h"


@interface FavouritesViewController ()
@property (weak, nonatomic) IBOutlet UITableView *favouritesTableView;
@property SongsSingleton* songSingleton;



@end

@implementation FavouritesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    [self.favouritesTableView registerNib:[UINib nibWithNibName:@"SongsCustomCell" bundle:nil]forCellReuseIdentifier:@"Songs"];
    self.favouritesTableView.dataSource = self;
    self.favouritesTableView.delegate = self;
    [self.favouritesTableView setOpaque:NO];
    [self.favouritesTableView setBackgroundColor:[UIColor clearColor]];
    self.songSingleton=[[SongsSingleton alloc]init];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reload) name:@"reload" object:nil];
}


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
-(void)reload{
    [self.favouritesTableView reloadData];
    
}

#pragma mark TableView config



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString* cellId = @"Songs";
    SongsCustomCell *cell = [self.favouritesTableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    cell.favouritesButton.hidden = YES;
    cell.songNameLabel.text=[self.songSingleton favoriteSongForIndex:indexPath.row].songName;
    cell.artistNameLabel.text=[self.songSingleton favoriteSongForIndex:indexPath.row].author;
    
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.songSingleton numberOfNotesInFavoriteSongs];;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 103;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SongViewController* SVC=[[SongViewController alloc]initWithNibName:@"SongViewController" bundle:nil];
    
    SVC.currentSong=[self.songSingleton favoriteSongForIndex:indexPath.row];
    SVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:SVC animated:YES completion:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





@end
